package foodmaterial.action;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import foodmaterial.config.ChoiceDataSource;
import foodmaterial.dto.OrdersDto;
import foodmaterial.entity.*;
import foodmaterial.service.HistoryOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/api/historyOrder")
@RestController
@CrossOrigin(allowCredentials = "true")
public class HistoryOrderAction extends BaseAction{

    @Autowired
    private HistoryOrderService service ;

    @PostMapping("/queryOrders")
    @ChoiceDataSource
    public JsonResult<PageInfo<Orders>> queryOrders(@RequestBody OrdersDto dto) {
        PageHelper.startPage(dto.getPageNo(),dto.getPageSize()) ;
        List<Orders> result = service.queryOrders(dto) ;
        PageInfo<Orders> pageInfo = new PageInfo<>(result) ;
        return new JsonResult(true, ResultCode.SUCCESS,pageInfo) ;
    }

    @GetMapping("/queryOrdersDetail")
    @ChoiceDataSource
    public JsonResult<List<OrdersDetail>> queryOrdersDetail(Long id) {
        List<OrdersDetail> result = service.queryOrdersDetail(id) ;
        return result.isEmpty()?
                new JsonResult(false, ResultCode.SUCCESS,null) :
                new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @GetMapping("/queryOrdersRecipe")
    @ChoiceDataSource
    public JsonResult<List<OrdersRecipe>> queryOrdersRecipe(Long id) {
        List<OrdersRecipe> result = service.queryOrdersRecipe(id) ;
        return result.isEmpty()?
                new JsonResult(false, ResultCode.SUCCESS,null) :
                new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

}
